﻿namespace Northwind.UI.WPF.AttachedBehaviors
{
    using System.Windows;

    public static class MainWindowAttachedBehaviors
    {
        #region Show Order Wizard

        public static DependencyProperty ShowOrderWizardProperty =
            DependencyProperty.RegisterAttached("ShowOrderWizard", typeof(bool),
            typeof(MainWindowAttachedBehaviors), 
            new UIPropertyMetadata(false, OnShowOrderWizard));


        public static bool GetShowOrderWizard(DependencyObject obj)
        {
            return (bool)obj.GetValue(ShowOrderWizardProperty);
        }

        public static void SetShowOrderWizard(DependencyObject obj, bool value)
        {
            obj.SetValue(ShowOrderWizardProperty, value);
        }

        public static void OnShowOrderWizard(DependencyObject d,
            DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                Window wnd = (Window)d;
                OrderWizard orderWizard = new OrderWizard();
                orderWizard.Owner = wnd;
                orderWizard.ShowDialog();
            }
        }
        
        #endregion

        #region Close Window

        public static DependencyProperty IsCloseViewProperty =
            DependencyProperty.RegisterAttached("IsCloseView", typeof(bool),
            typeof(MainWindowAttachedBehaviors), 
            new UIPropertyMetadata(false, OnIsCloseView));


        public static bool GetIsCloseView(DependencyObject obj)
        {
            return (bool)obj.GetValue(IsCloseViewProperty);
        }

        public static void SetIsCloseView(DependencyObject obj, bool value)
        {
            obj.SetValue(IsCloseViewProperty, value);
        }

        public static void OnIsCloseView(DependencyObject d,
            DependencyPropertyChangedEventArgs e)
        {
            Window wnd = (Window)d;
            if ((bool)e.NewValue)
            {
                wnd.Close();
            }
        }

        #endregion
    }
}
